package com.aaron.springScan.spring;

import com.aaron.springScan.annotation.MyServiceTest;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.core.type.filter.AnnotationTypeFilter;

/**
 * @ClassName MyBeanDefintionRegistryPostProcessor
 * @description:
 * @author: 荣燊
 * @create: 2021-06-30 15:39
 **/
public class MyBeanDefintionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor {

    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException {
        //
        String[] beanDefintionNames = beanDefinitionRegistry.getBeanDefinitionNames();

        for(String beanDefinitonName : beanDefintionNames){
            BeanDefinition beanDefinition = beanDefinitionRegistry.getBeanDefinition(beanDefinitonName);
            System.out.println(beanDefinition.getAttribute("key"));
        }

        //定义一个扫描器
        ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(beanDefinitionRegistry);
        scanner.addIncludeFilter(new AnnotationTypeFilter(MyServiceTest.class));
        scanner.scan("com.aaron.springScan.annotation");
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {

    }
}
